import { Model, DataTypes, Optional } from 'sequelize';
// import sequelize from '@/core/db';
import sequelize from '../../core/db';
interface BlockAttritubes {
  id: string;
  title: string;
  coverImage: string;
  editorType: 1 | 2 | 3;
  isTop: 0 | 1;
  hasComment: 0 | 1;
  content: string;
  authorId: string;
  author: string;
  collectionId: string | null;
  collection: string | null;
  tagId: string | null;
  tag: string | null;
  remark_1: string | null;
  remark_2: string | null;
}

interface BlockCreationAttributes extends Optional<BlockAttritubes, 'id'> {}

class BlockModel
  extends Model<BlockAttritubes, BlockCreationAttributes>
  implements BlockAttritubes
{
  public id!: string;
  public title!: string;
  public coverImage!: string;
  public editorType!: 1 | 2 | 3;
  public isTop!: 0 | 1;
  public hasComment!: 0 | 1;
  public content!: string;
  public authorId!: string;
  public author!: string;
  public collectionId!: string;
  public collection!: string;
  public tagId!: string;
  public tag!: string;
  public remark_1!: string;
  public remark_2!: string;
}

BlockModel.init(
  {
    id: {
      type: DataTypes.UUID,
      primaryKey: true,
    },
    title: DataTypes.STRING,
    coverImage: DataTypes.STRING,
    editorType: DataTypes.INTEGER,
    isTop: DataTypes.INTEGER,
    hasComment: DataTypes.INTEGER,
    content: DataTypes.STRING,
    authorId: DataTypes.STRING,
    author: DataTypes.STRING,
    collectionId: DataTypes.STRING,
    collection: DataTypes.STRING,
    tagId: DataTypes.STRING,
    tag: DataTypes.STRING,
    remark_1: DataTypes.STRING,
    remark_2: DataTypes.STRING,
  },
  {
    sequelize,
    tableName: 'block',
  }
);

class Block {
  get BlockModel() {
    return BlockModel;
  }
  async create(params: BlockAttritubes) {
    await BlockModel.create(params);
  }
  async destroy(params: string[]) {
    await BlockModel.destroy({
      where: {
        id: params,
      },
    });
  }
}

export default Block;
export { BlockAttritubes };